#include "DrawingPanel.h"
#include <time.h>

BEGIN_EVENT_TABLE(DrawingPanel, wxPanel)
	EVT_PAINT(DrawingPanel::PaintEvent)
	EVT_MOTION(DrawingPanel::OnMotion)
END_EVENT_TABLE()

	DrawingPanel::DrawingPanel(wxFrame *parent) : wxPanel(parent)
{
	_scene = new Scene();
}

void DrawingPanel::PaintEvent(wxPaintEvent &evt)
{
	wxBufferedPaintDC dc(this);
	PrepareDC(dc);
	PaintBackground(dc);
	dc.SetBrush(wxBrush(wxColour("White")));
	dc.SetPen(wxPen(wxColour("Black"), 1));
	Render(dc);
}
/// Paint the background
void DrawingPanel::PaintBackground(wxDC& dc)
{
	wxColour backgroundColour = GetBackgroundColour();
	if (!backgroundColour.Ok())
		backgroundColour =
		wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);

	dc.SetBrush(wxBrush(backgroundColour));
	dc.SetPen(wxPen(backgroundColour, 1));

	wxRect windowRect(wxPoint(0, 0), GetClientSize());    
	dc.DrawRectangle(windowRect);
}

void DrawingPanel::Idle()
{
	if(_scene->IsGame())
	{
		_scene->Idle();
		GameRectangle rect = _scene->getArene()->Englobant();
		RefreshRect(wxRect(rect.BL.X,0,rect.Largeur(),rect.Hauteur()+rect.TR.Y),false);
	}
}
void DrawingPanel::OnMotion(wxMouseEvent &evt)
{
	_scene->SetMouseCoord(evt.GetX(),evt.GetY());
	evt.Skip();
}
void DrawingPanel::Render(wxDC &dc)
{
	_scene->Render(dc);
}

DrawingPanel::~DrawingPanel(void)
{
	if(_scene!=NULL)
		delete _scene;
}
